package com.mh.study.streams;

import java.util.Arrays;
import java.util.OptionalInt;
import java.util.stream.IntStream;
import java.util.stream.Stream;

/**
 * @author meng.han
 * @since 2022-01-26
 */
public class StreamReduce {

    public OptionalInt reduced() {
        return IntStream.range(1, 4).reduce(Integer::sum);
    }

    public int reducedTwoParams() {
        return IntStream.range(1, 4).reduce(10, Integer::sum);
    }

    public int reducedThreeParams() {
        return Stream.of(1, 2, 3).reduce(10, Integer::sum, Integer::sum);
    }

    public int parallelReducedThreeParams() {
        return Arrays.asList(1, 2, 3).parallelStream()
                .reduce(10, Integer::sum, Integer::sum);
    }

}
